#ifndef _GAMELAB_SIGLETON_H
#define _GAMELAB_SIGLETON_H

///////////////////////////////////////////////////
//
// Design Pattern: Singleton(thread safe)
//
///////////////////////////////////////////////////

template <typename T>
class Singleton
{
	public:

		/**
		 * Scott Meyers 's implemention.
		 * Static varible instantiated only once,return as 
		 * reference because caller probably will delete it.
		 */
		static T& Instance()
		{
			static T instance;
			return instance;
		}

	protected:
		Singleton() {}
		~Singleton() {}
};

///////////////////////////////////////////////////
//
// Design Pattern: Singleton(thread safe)
//
///////////////////////////////////////////////////
template <typename T>
class LazySingleton
{
	public:
		static T& instance()
		{
			if(0 == _instance)
				_instance = new T;

			return *_instance;
		}

		/*
		   static T * instance()
		   {
		   if(0 == _instance)
		   _instance = new T;

		   return _instance;
		   }*/

	protected:
		LazySingleton() {}
		~LazySingleton() 
		{
			if(_instance)
				delete _instance;
			_instance = 0;
		}

	private:
		static T * _instance;
};

template<typename T>
T * LazySingleton<T>::_instance = 0;

#endif // _GAMELAB_SIGLETON_H
